using System.Collections;
// using Sirenix.OdinInspector;
// using Spine;
using UnityEngine;
// using Cfg;
// using PrimeTween;
public class GameRoot : MonoBehaviour
{
    public static GameRoot Inst { get; private set; }
    private void Awake()
    {
        Inst = this;
        DontDestroyOnLoad(this);
    }

    public bool useAB;

    // [ReadOnly]
    public bool readMainAB;
    // [ReadOnly]
    public bool readSpineDepend;
    private void Start()
    {
        // PrimeTweenConfig.warnZeroDuration = false;
        Application.targetFrameRate = 60;
#if UNITY_EDITOR
        // ConfReader.Inst.Init();
        // SkeletonDataMgr.Inst.Init();
        readSpineDepend = true;
        readMainAB = true;
#else
        StartCoroutine(LoadMain());
#endif
    }

    private IEnumerator LoadMain()
    {
        if (!AssetsMgr.Inst.IsMainifestLoaded())
        {
            Debug.Log("start download mainifest");
            yield return StartCoroutine(AssetsMgr.Inst.DownloadManifest());
            Debug.Log("end download mainifest");
        }

        bool downloadConfEnd = false;
        StartCoroutine(AssetsMgr.Inst.DownloadAssetBundle("confjson", () =>
        {
            downloadConfEnd = true;
        }));

        yield return new WaitUntil(() => downloadConfEnd);

        readMainAB = true;
        StartCoroutine(LoadSpineDatabase());
    }

    private IEnumerator LoadSpineDatabase()
    {
        // st mean something，加上文件名是为了正确触发获取文件夹
        yield return StartCoroutine(AssetsMgr.Inst.DownloadAssetBundle("database"));
        yield return StartCoroutine(AssetsMgr.Inst.DownloadAssetBundle("spine-unity/gui"));
        yield return StartCoroutine(AssetsMgr.Inst.DownloadAssetBundle("spine-unity/materials"));
        yield return StartCoroutine(AssetsMgr.Inst.DownloadAssetBundle("spine-unity/shaders"));
        // SkeletonDataMgr.Inst.Init();
        readSpineDepend = true;
    }

    private void Update()
    {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Debug.Break();
        }
#endif
    }
}